#include"Number.h"
CNumber::CNumber()
{
	number=NULL;
	image=NULL;
	for(int i=0;i<6;i++) score[i]=0;
	coins[0]=coins[1]=0;
}
CNumber::~CNumber()
{
	if(number!=NULL) delete number;
	if(image!=NULL) image->Release();
}
LPDIRECT3DTEXTURE9 CNumber::GetImage(LPDIRECT3DDEVICE9 d3ddv, LPWSTR filename)
{
	D3DXIMAGE_INFO info;
	LPDIRECT3DTEXTURE9 image;
	HRESULT result= D3DXGetImageInfoFromFile(filename,&info);
	if(result!=D3D_OK) return NULL;
	D3DXCreateTextureFromFileEx(d3ddv,filename,info.Width,info.Height,1,D3DPOOL_DEFAULT,D3DFMT_UNKNOWN,D3DPOOL_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,D3DCOLOR_XRGB(0,0,0),&info,NULL,&image);
	return image;
}
void CNumber::LoadResources(LPDIRECT3DDEVICE9 d3ddv)
{
	image=GetImage(d3ddv,L"Image\\numbers.png");
}
void CNumber::RenderIntro(LPD3DXSPRITE sprite,int stage,int life)
{
	number=new CSprite(true,stage*19,0,19,20,0,0,0);
	number->Render(sprite,image,350,210);
	number=new CSprite(true,life*19,0,19,20,0,0,0);
	number->Render(sprite,image,350,250);
	number=new CSprite(true,190,0,19,20,0,0,0);
	number->Render(sprite,image,320,250);
}
void CNumber::Render(LPD3DXSPRITE sprite,int timeplay,int _score,int _coins, int _stage)
{
	time[0]=timeplay/100;
	time[1]=(timeplay%100)/10;
	time[2]=timeplay-time[0]*100-time[1]*10;
	for(int i=0;i<3;i++)
	{
		number=new CSprite(true,time[i]*19,0,19,20,0,0,0);
		number->Render(sprite,image,515+i*15,30);
	}
	scores=_score/100;
	score[0]=scores/1000;
	score[1]=(scores-score[0]*1000)/100;
	score[2]=(scores-score[0]*1000-score[1]*100)/10;
	score[3]=scores-score[0]*1000-score[1]*100-score[2]*10;
	for(int i=0;i<6;i++)
	{
		number=new CSprite(true,score[i]*19,0,19,20,0,0,0);
		number->Render(sprite,image,20+i*15,30);
	}
	coins[0]=_coins/10;
	coins[1]=_coins-coins[0]*10;
	for(int i=0;i<2;i++)
	{
		number=new CSprite(true,coins[i]*19,0,19,20,0,0,0);
		number->Render(sprite,image,180+i*15,10);
	}
	number=new CSprite(true,190,0,19,20,0,0,0);
	number->Render(sprite,image,160,10);
	number=new CSprite(true,_stage*19,0,19,20,0,0,0);
	number->Render(sprite,image,340,30);
}